package com.cy.pj.sys.web响应标准和全局异常处理;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j //日志导入
@RestControllerAdvice //相当于@ControllerAdvice+@ResponseBady
public class GlobalExceptionHandler {

    @ExceptionHandler(NumberFormatException.class)
    public JsonResult doNumberFormatException(NumberFormatException e) {
        e.printStackTrace();
        log.error("exception {}", "传入的参数类型不匹配");
        return new JsonResult(0, "传入的参数类型不匹配");

    }

    @ExceptionHandler(RuntimeException.class)
    public JsonResult doHandleRuntimeException(RuntimeException e) {
        e.printStackTrace();
        log.error("exception {}", e.getMessage());
        return new JsonResult(e);
    }
}
